package io.zcoder.innoway.fragments;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.zcoder.innoway.R;
import io.zcoder.innoway.widgets.TextViewCustom;

public class InfoFragment extends BaseFragment {

    @BindView(R.id.common_male)
    ImageView mMaleIcon;
    @BindView(R.id.common_female)
    ImageView mFeMaleIcon;
    @BindView(R.id.layout_fat)
    LinearLayout mLayoutFat;
    @BindView(R.id.layout_water)
    LinearLayout mLayoutWater;
    @BindView(R.id.layout_cal)
    LinearLayout mLayoutCal;
    private boolean isMale = false;

    @OnClick(R.id.common_male)
    void selectMale() {
        mMaleIcon.setImageResource(R.drawable.ic_info_male_selected);
        mFeMaleIcon.setImageResource(R.drawable.ic_info_female);
        isMale = true;
        setViews();
    }

    @OnClick(R.id.common_female)
    void selectFeMale() {
        mFeMaleIcon.setImageResource(R.drawable.ic_info_female_selected);
        mMaleIcon.setImageResource(R.drawable.ic_info_male);
        isMale = false;
        setViews();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_info_fragment, container, false);
        ButterKnife.bind(this, view);
        mMaleIcon.setVisibility(View.VISIBLE);
        mFeMaleIcon.setVisibility(View.VISIBLE);
        setTitle(getString(R.string.info));

        setViews();
        return view;
    }

    private void setViews() {
        String[] fat_water_age = getResources().getStringArray(R.array.fat_water_age);
        String[] fat_under_weight = getResources().getStringArray(R.array.fat_female_under_weight);
        String[] fat_normal = getResources().getStringArray(R.array.fat_female_normal);
        String[] fat_over_weight = getResources().getStringArray(R.array.fat_female_over_weight);
        String[] fat_obese = getResources().getStringArray(R.array.fat_female_obese);
        String[] water_under_weight = getResources().getStringArray(R.array.water_female_low);
        String[] water_normal = getResources().getStringArray(R.array.water_female_normal);
        String[] water_over_weight = getResources().getStringArray(R.array.water_female_height);
        if (isMale) {
            fat_under_weight = getResources().getStringArray(R.array.fat_male_under_weight);
            fat_normal = getResources().getStringArray(R.array.fat_male_normal);
            fat_over_weight = getResources().getStringArray(R.array.fat_male_over_weight);
            fat_obese = getResources().getStringArray(R.array.fat_male_obese);
            water_under_weight = getResources().getStringArray(R.array.water_male_low);
            water_normal = getResources().getStringArray(R.array.water_male_normal);
            water_over_weight = getResources().getStringArray(R.array.water_male_height);
        }
        mLayoutFat.removeAllViews();
        mLayoutWater.removeAllViews();
        for (int i = 0; i < 5; i++) {
            View view = View.inflate(getActivity(), R.layout.item_bmi_fat, null);
            TextViewCustom v1 = (TextViewCustom) view.findViewById(R.id.bmi_text_1);
            TextViewCustom v2 = (TextViewCustom) view.findViewById(R.id.bmi_text_2);
            TextViewCustom v3 = (TextViewCustom) view.findViewById(R.id.bmi_text_3);
            TextViewCustom v4 = (TextViewCustom) view.findViewById(R.id.bmi_text_4);
            TextViewCustom v5 = (TextViewCustom) view.findViewById(R.id.bmi_text_5);
            v5.setVisibility(View.VISIBLE);
            v1.setText(fat_water_age[i]);
            v2.setText(fat_under_weight[i]);
            v3.setText(fat_normal[i]);
            v4.setText(fat_over_weight[i]);
            v5.setText(fat_obese[i]);
            mLayoutFat.addView(view);
            View view2 = View.inflate(getActivity(), R.layout.item_bmi_water, null);
            TextViewCustom v21 = (TextViewCustom) view2.findViewById(R.id.bmi_text_1);
            TextViewCustom v22 = (TextViewCustom) view2.findViewById(R.id.bmi_text_2);
            TextViewCustom v23 = (TextViewCustom) view2.findViewById(R.id.bmi_text_3);
            TextViewCustom v24 = (TextViewCustom) view2.findViewById(R.id.bmi_text_4);
            v5.setVisibility(View.VISIBLE);
            v21.setText(fat_water_age[i]);
            v22.setText(water_under_weight[i]);
            v23.setText(water_normal[i]);
            v24.setText(water_over_weight[i]);
            mLayoutWater.addView(view2);
        }
        mLayoutCal.removeAllViews();
        for (int i = 0; i < 10; i++) {
            String[] water_age = getResources().getStringArray(R.array.cal_age);
            String[] water_value = getResources().getStringArray(R.array.cal_female_value);
            if (isMale) {
                water_value = getResources().getStringArray(R.array.cal_male_value);
            }

            View view = View.inflate(getActivity(), R.layout.item_bmi_cal, null);
            TextViewCustom v1 = (TextViewCustom) view.findViewById(R.id.bmi_text_1);
            TextViewCustom v2 = (TextViewCustom) view.findViewById(R.id.bmi_text_2);
            v1.setText(water_age[i]);
            v2.setText(water_value[i]);
            mLayoutCal.addView(view);
        }
    }
}
